package com.company.dcm.utils;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;

/**
 * @author BailuGansan
 * @email 1195137943@qq.com
 */
public class HttpRequestUtils {

    /**
     * 获取当前 HTTP 请求
     */
    public static HttpServletRequest getRequest(){
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        return attributes.getRequest();
    }

    /**
     * 获取 HttpServletRequest
     */
    public static HttpServletRequest toHttp(ServletRequest servletRequest){
        return (HttpServletRequest) servletRequest;
    }
}
